class Node{
    constructor(value,next=null,prev=null){
        this.value = value;
        this.next = next; //后继指针
        this.prev = prev; //前继指针
    }
}

let a = new Node(1);
let b = new Node(2);
let c = new Node(3);
let d = new Node(4);

a.next = b;
b.prev = a;
b.next = c;
c.prev = b;
c.next = d;
d.prev = c;

//先搞一个双向链表

//双向链表倒置只需改变两个指针的指向即可
function reverseList(head){
    let prev = null;
    let cur = head;
    while(cur){
        const next = cur.next;  //将当前节点的下一个节点存起来
        // cur.next = prev; //将当前节点的下一个节点指向上一个节点
        // cur.prev = next; //将当前节点的上一个节点指向下一个节点
        [cur.next,cur.prev] = [cur.prev,cur.next]; //交换当前节点的next和prev,解构赋值
        prev = cur; //将prev指向当前节点
        cur = next;
    }
    return prev;
}


//test
console.log('原始链表:')
console.log(a)
console.log('逆置后的链表:')
console.log(reverseList(a))